package tour.board.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Repository;




import board.util.Utilities;


import tour.board.to.EpBoard;
import tour.board.to.ReEpBoard;
import tour.board.to.RecommendTO;
import board.util.Utilities;

@Repository
public class EpBoardDAOImpl implements EpBoardDAO{

	@Autowired
	private SqlMapClientTemplate sqlMap;
	
	
	public void setSqlMap(SqlMapClientTemplate sqlMap) {
		this.sqlMap = sqlMap;
	}


	@Override
	public Object insertContentForNewCount(EpBoard epBoard) throws SQLException {
		return sqlMap.insert("eboard.insertContentForNewCount", epBoard);
	}


	@Override
	public Object insertContentForReply(EpBoard epBoard) throws SQLException {
		return sqlMap.insert("eboard.insertContentForReply", epBoard);
	}


	@Override
	public ArrayList<EpBoard> selectBoardListByPage(int page)
			throws SQLException {
		HashMap map = new HashMap();
		map.put("contentPerPage", Utilities.CONTENT_PER_PAGE);
		map.put("page", page);
		return (ArrayList<EpBoard>)sqlMap.queryForList("eboard.selectBoardListByPage", map);
	}


	@Override
	public ArrayList<EpBoard> selectBoardAllList() throws SQLException {
		return (ArrayList<EpBoard>)sqlMap.queryForList("eboard.selectBoardAllList");
	}


	@Override
	public int selectTotalContent() throws SQLException {
		return (Integer)sqlMap.queryForObject("eboard.selectTotalContent");
	}


	@Override
	public int updateViewCount(int no) throws SQLException {
		return sqlMap.update("eboard.updateViewCount", no);
	}


	@Override
	public EpBoard selectContentByNO(int no) throws SQLException {
		return (EpBoard)sqlMap.queryForObject("eboard.selectContentByNO", no);
	}


	@Override
	public int updateContent(EpBoard epBoard) throws SQLException {
		return sqlMap.update("eboard.updateContent", epBoard);
	}


	@Override
	public int deleteContentByNO(int no) throws SQLException {
		return sqlMap.delete("eboard.deleteContentByNO", no);
	}


	@Override
	public int updateRestep(int refamily, int restep) throws SQLException {
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		map.put("refamily", refamily);
		map.put("restep", restep);
		return sqlMap.update("eboard.updateRestep", map);
	}


	@Override
	public ArrayList replyList() {
		return (ArrayList) sqlMap.queryForList("eboard.replyList");
	}


	@Override
	public void addReply(ReEpBoard reEpBoard) {
		sqlMap.insert("eboard.addReply", reEpBoard);
	}


	@Override
	public ArrayList getReplyByNo(int no) {
		return (ArrayList)sqlMap.queryForList("eboard.getReplyByNo",no);
	}
	
	//추천
	@Override
	public String recommend(RecommendTO rto) throws SQLException{
		return (String)sqlMap.queryForObject("eboard.recommend", rto);		
	}
	@Override
	public void updateCommendCount(int no) throws SQLException{
		sqlMap.update("eboard.updateCommendCount", no);
	}
	
	@Override
	public void insertRecommendInfo(RecommendTO rto) throws SQLException{
		sqlMap.insert("eboard.insertRecommendInfo", rto);		
	}


	@Override
	public ArrayList mainList(){
		return (ArrayList)sqlMap.queryForList("eboard.mainList");
	}


	@Override
	public ArrayList findWriter(String find) {
		return (ArrayList)sqlMap.queryForList("eboard.findWriter",find);
	}


	@Override
	public ArrayList findTitle(String find) {
		System.out.println(sqlMap.queryForList("eboard.findTitle"));
		return (ArrayList)sqlMap.queryForList("eboard.findTitle",find);
	}
}
